<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <style></style>
  </head>
  <body>
    <div>
      <h1>减少判断层级</h1>
    </div>
    <script>
      //减少层级判断的代码快于没减少的
      function doSomething(part, chapter) {
        const parts = ["ES2016", "工程化", "Vue", "React", "Node"];
        if (part) {
          if (parts.includes(part)) {
            console.log("没有该课程");
            if (chapter > 5) {
              console.log("你不是vip");
            }
          }
        } else {
          console.log("没有输出课程");
        }
      }

      doSomething("ES2016", 6);

      //减少判断层级
      function doSomething1(part, chapter) {
        const parts = ["ES2016", "工程化", "Vue", "React", "Node"];
        if (!parts) {
          console.log("没有输出课程");
          return;
        }
        if (!parts.includes(part)) return;
        console.log("没有该课程");
        if (chapter > 5) {
          console.log("你不是vip");
        }
      }

      doSomething1("ES2016", 6);
    </script>
  </body>
</html>
